package org.ccay.excel.importer.validate.impl;

import org.ccay.core.util.StringUtil;
import org.ccay.excel.importer.validate.AbstractValidator;
import org.ccay.excel.importer.validate.IStatus;

/**
 * 条件非空校验器。
 * 
 * @author chaowangbang
 * @since Mar 27, 2012
 */
public class ConditionRequiredValidator extends AbstractValidator {
	
	public static final String MESSAGE_KEY = "ccay.excel.validate.required.error";

	// 条件列
	private String title;
    //否和的条件value 
    private String values;
    //条件value的分隔符
    private String split =",";
	/* (non-Javadoc)
	 * @see org.ccay.excel.importer.validate.IValidator#validate(java.lang.String, org.ccay.excel.importer.validate.IValidationContext)
	 */
	public IStatus doValidate(Object value) {
		String conditionValue = super.getTitleValue(title);
		String[] valuess = this.values.split(split);
		for (String string : valuess) {
			if(conditionValue.equals(string)){
				if(value==null || StringUtil.isNullOrEmpty(value.toString().trim())) {
					return error();
				}
			}
		}
		return IStatus.Ok;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	
	public String getValues() {
		return values;
	}
	public void setValues(String values) {
		this.values = values;
	}
	public String getSplit() {
		return split;
	}
	public void setSplit(String split) {
		this.split = split;
	}

	
}
